package com.zy.springboot.dao.book;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.springboot.dao.BaseDao;
import com.zy.springboot.entity.IBaseEntity;
import com.zy.springboot.entity.book.RecordsEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by y on 2019/1/11.
 */
@Repository
public class RecordsDao extends BaseDao {

    public RecordsDao(){
        super.iBaseEntity = new RecordsEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json,RecordsEntity.class);
    }

    public List<JSONObject> check(String bookId, String openId){
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT id,index2 FROM T_SYS_RECORDS where  bookId='"+bookId+"' and openId='"+openId+"'  and del_flag=0 ");
        return super.queryForJsonList(sql.toString());
    }
    public List<JSONObject> getList( String openId){
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT T_SYS_BOOK.id AS bookId,T_SYS_BOOK.bookName AS bookName,");
        sql.append(" T_SYS_BOOK.imgUrl as imgUrl,T_SYS_RECORDS.index2 AS index2,T_SYS_RECORDS.UPDATE_TIME as updateTime ");
        sql.append(" FROM T_SYS_RECORDS");
        sql.append(" LEFT JOIN T_SYS_USER ON T_SYS_RECORDS.openid = T_SYS_USER.openid");
        sql.append(" LEFT JOIN T_SYS_BOOK ON T_SYS_RECORDS.bookId = T_SYS_BOOK.id\n");
        sql.append(" WHERE ");
        sql.append(" T_SYS_USER.openid = '"+openId+"' AND T_SYS_RECORDS.del_flag = 0 ");
        sql.append(" ORDER BY T_SYS_RECORDS.UPDATE_TIME DESC");
        return super.queryForJsonList(sql.toString());
    }

}
